home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / boot / i386 / loader / biostest / biostest 4585 / usr / share / firmwarekit / plugins / thermal_trip.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2006-11-29  |  7KB  |  220 lines

  1. #!/bin/bash
  2. #***************************************************************************
  3. #*                                                                         *
  4. #*         Check-Tool if acpi passive trip_points are supported            *
  5. #*                                                                         *
  6. #*            Copyright (C) 2006 SUSE Linux Products GmbH                  *
  7. #*                                                                         *
  8. #*             Author(s): Frank Seidel <fseidel@suse.de>                   *
  9. #*        Modified by: Arjan van de Ven <arjan@linux.intel.com>      *
  10. #*                          integration with the LFDK shell API            *
  11. #*                                                                         *
  12. #* This program is free software; you can redistribute it and/or modify it *
  13. #* under the terms of the GNU General Public License as published by the   *
  14. #* Free Software Foundation; either version 2 of the License, or (at you   *
  15. #* option) any later version.                                              *
  16. #*                                                                         *
  17. #* This program is distributed in the hope that it will be useful, but     *
  18. #* WITHOUT ANY WARRANTY; without even the implied warranty of              *
  19. #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
  20. #* General Public License for more details.                                *
  21. #*                                                                         *
  22. #* You should have received a copy of the GNU General Public License along *
  23. #* with this program; if not, write to the Free Software Foundation, Inc., *
  24. #* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA                  *
  25. #*                                                                         *
  26. #***************************************************************************/
  27.  
  28. export THERMALPATH="/proc/acpi/thermal_zone"
  29. export THROTTLINGPATH="$(echo /proc/acpi/processor/* |head -n 1)/throttling"
  30. export CPUFREQPATH="$(echo /sys/devices/system/cpu/* |head -n 1)/cpufreq"
  31. export OUTPUTTYPE="d"
  32.  
  33. function printhelp ()
  34. {
  35.     cat <<-EOHELP
  36.     This script tries to determine if the passive trip point (given by
  37.     the acpi interace in /proc) does work as expected.
  38.     Following options can be given: 
  39.  
  40.     -h        This help you are looking at
  41.     -s        Show only names of supported thermal_zones
  42.     -u        Show only names of un-supported thermal_zones
  43.     -d        Debug output (default)
  44. EOHELP
  45. }
  46.  
  47.  
  48. #eval given opts
  49.  
  50. while getopts "hsud" optchar
  51. do
  52.     case "$optchar" in
  53.         h)
  54.             printhelp
  55.             exit 0
  56.             ;;
  57.         s)
  58.             export OUTPUTTYPE="s"
  59.             ;;
  60.         u)
  61.             export OUTPUTTYPE="u"
  62.             ;;
  63.         d)
  64.             export OUTPUTTYPE="d"
  65.             ;;
  66.         *)
  67.             echo "Unknown option" >&2
  68.             printhelp 
  69.             exit 1
  70.             ;;
  71.     esac
  72. done
  73.  
  74.  
  75. start_test thermal_trip "ACPI passive thermal trip points" \
  76. "This test determines if the passive trip point works as expected."
  77.  
  78. #Go through zones
  79. for ZONE in $THERMALPATH/*
  80. do
  81.     #check if passive trip point is shown at all
  82.  
  83.     if (grep passive "$ZONE/trip_points" &>/dev/null )
  84.     then
  85.         #save current temps
  86.         CUR_PASSIVE="$(grep passive $ZONE/trip_points |sed -e 's/passive:[^0-9]*\([0-9]*\) C.*/\1/')"
  87.         #critical trip point
  88.         if (grep critical "$ZONE/trip_points" &>/dev/null)
  89.         then
  90.             export CUR_CRITICAL="$(grep critical $ZONE/trip_points |sed -e 's/critical (S5):[^0-9]*\([0-9]*\) C.*/\1/')"
  91.         else
  92.             export CUR_CRITICAL="0"
  93.         fi
  94.         #hot trip point
  95.         if (grep "^hot" "$ZONE/trip_points" &>/dev/null    )
  96.         then
  97.             export CUR_HOT="$(grep '^hot' $ZONE/trip_points |sed -e 's/hot[^\:]*:[^0-9]*\([0-9]*\) C.*/\1/')"
  98.         else
  99.             export CUR_HOT="0"
  100.         fi
  101.         #active trip points
  102.         if (grep "^active" "$ZONE/trip_points" &>/dev/null)
  103.         then
  104.             export CUR_ACTIVES="$(grep '^active' $ZONE/trip_points | sed -e 's/active[^\:]*:[^0-9]*\([0-9]*\) C.*/\1/' | tr '\n' ':')0"
  105.         else
  106.             export CUR_ACTIVES="0:0"
  107.         fi
  108.  
  109.         
  110.  
  111.         #look for current throttling on first cpu
  112.         CUR_THROT="$(grep active $THROTTLINGPATH |sed 's/active[^T]*T\([0-9]*\)/\1/')"
  113.  
  114.         #look for current cpufreq state
  115.         if [ -d "$CPUFREQPATH" ]
  116.         then
  117.             #..and start stressing cpu to to see wheather it gets scaled down
  118.             exec 2>/dev/null
  119.             cat /dev/zero >/dev/null &
  120.             export STRESSPID=$!
  121.  
  122.             sleep 3
  123.             
  124.             #cpu should be stressed now and current freq high
  125.             export CUR_CPUFREQ="$( <$CPUFREQPATH/scaling_cur_freq)"
  126.         fi
  127.  
  128.         #look for current polling frequency
  129.         CUR_POLLING="$(sed -e 's/polling[^0-9]*\([0-9]*\) sec.*/\1/' $ZONE/polling_frequency)"
  130.  
  131.         #set new trip points
  132.         echo "$CUR_CRITICAL:$CUR_HOT:20:$CUR_ACTIVES" > $ZONE/trip_points
  133.         #mess current polling to get kernels attention
  134.         echo 1 >$ZONE/polling_frequency
  135.         echo 2 >$ZONE/polling_frequency
  136.         echo $CUR_POLLING >$ZONE/polling_frequency &> /dev/null
  137.  
  138.         #give the kernel some time
  139.         sleep 4
  140.  
  141.         #recheck throttling now
  142.         NEW_THROT="$(grep active $THROTTLINGPATH |sed 's/active[^T]*T\([0-9]*\)/\1/')"
  143.         #recheck cpufreq now
  144.         if [ -d "$CPUFREQPATH" ]
  145.         then
  146.             export NEW_CPUFREQ="$( <$CPUFREQPATH/scaling_cur_freq)"
  147.  
  148.             #and stop stressing cpu
  149.             kill $STRESSPID
  150.             set -m
  151.         fi
  152.  
  153.         #check for difference
  154.         if ( [ "$NEW_THROT" -gt "$CUR_THROT" ] || [ "$NEW_CPUFREQ" -lt "$CUR_CPUFREQ" ] )
  155.         then
  156.             #yes, throttling is effective
  157.             case "$OUTPUTTYPE" in
  158.                 d)
  159.                     if [ -n "$NEW_CPUFREQ" ]
  160.                     then
  161.                         report_result thermal_trip PASS "Zone ${ZONE##*/} supports passive trip point (throttled from T$CUR_THROT to T$NEW_THROT / cpufreq scaling from $CUR_CPUFREQ to $NEW_CPUFREQ kHz)."
  162.                     else
  163.                         report_result thermal_trip PASS "Zone ${ZONE##*/} supports passive trip point (throttled from T$CUR_THROT to T$NEW_THROT)."
  164.                     fi
  165.                     ;;
  166.                 s)
  167.                     echo "${ZONE##*/}"
  168.                     ;;
  169.                 u)     ;;
  170.                 *)
  171.                     echo "Internal error: unknown OUTPUTTYPE $OUTPUTTYPE." >&2
  172.                     exit 1
  173.                     ;;
  174.             esac
  175.         else
  176.             #no, throttling is not effective
  177.             case "$OUTPUTTYPE" in
  178.                 d)
  179.                     report_result thermal_trip FAIL "Changing passive trip point seems uneffective in Zone ${ZONE##*/}."
  180.                     ;;
  181.                 u)
  182.                     echo "${ZONE##*/}"
  183.                     ;;
  184.                 s)    ;;
  185.                 *)
  186.                     echo "Internal error: unknown OUTPUTTYPE $OUTPUTTYPE." >&2
  187.                                         exit 1
  188.                                         ;;
  189.             esac
  190.         fi
  191.  
  192.         #restor old values
  193.         echo "$CUR_CRITICAL:$CUR_HOT:$CUR_PASSIVE:$CUR_ACTIVES" >$ZONE/trip_points
  194.         echo 1 >$ZONE/polling_frequency
  195.                 echo 2 >$ZONE/polling_frequency
  196.                 echo $CUR_POLLING >$ZONE/polling_frequency &> /dev/null
  197.         sleep 4
  198.  
  199.     else
  200.         #cannot check as passive trip points are not supported
  201.         case "$OUTPUTTYPE" in
  202.             d)
  203.                 report_result thermal_trip WARN "Zone ${ZONE##*/} doesn't support passive trip point at all." 
  204.                 ;;
  205.             u)
  206.                 echo "${ZONE##*/}"
  207.                 ;;
  208.             s)    ;;
  209.             *)
  210.                 echo "Internal error: unknown OUTPUTTYPE $OUTPUTTYPE." >&2
  211.                 exit 1
  212.                 ;;
  213.         esac
  214.     fi
  215.  
  216.  
  217. done
  218.  
  219. finish_test thermal_trip
  220.